import {createSlice} from '@reduxjs/toolkit'
const initialState = {value:0}
export const counterSlice = createSlice({
  name:"counter", //名称
  initialState,//初始数据
  reducers:{//处理器
    increment:state=>{state.value+=1},
    decrement:state=>{state.value-=1},
    addValue:(state,action)=>{
      state.value+=action.payload
    }
  }
})
// 导出动作
export const {increment,decrement,addValue} = counterSlice.actions;
// 导出处理器
export default counterSlice.reducer

// 异步处理
export const addSync=amount=>(dispatch)=>{
  setTimeout(()=>{
    dispatch(addValue(amount))
  },2000)
} 